<template>
	<view class="list-container">
		<view class="newlist">
			<newList
			:list="list"
			imgField="course_img"
			titleField="course_title"
			tipsField="tipsHtml"
			@handleClick="gohref"
			></newList>
			<!-- numField="num" -->
		</view>
	</view>
</template>

<script>
	import newList from "../../components/new_list/index.vue";
	import {getStudy,getCollect} from "../../static/js/api/user.js";
	export default{
		components:{
			newList
		},
		data(){
			return{
				list:[], 
			}
		},
		onLoad(option) {
			if(option.type=="study"){
				uni.setNavigationBarTitle({
					title:"观看记录"
				})
				this.getStudyData()
			}else{
				uni.setNavigationBarTitle({
					title:"我的收藏"
				})
				this.getCollectData()
			}
		},
		methods:{
			gohref(item){
				console.log(item)
				uni.navigateTo({
					url:"/pages/basicCourse/course?courseInfo="+JSON.stringify(item)
				})
			},
			getCollectData(){
				let _this = this
				_this.list = []
				getCollect({
					page:1,
					per_page:9999
				}).then(res=>{
					console.log(res)
					if(res.courses){
						res.courses.forEach(item=>{
							if(item.category_title){
								item.tipsHtml = "类型 "+item.category_title
							}
						})
						_this.list = res.courses
					}
				})
			},
			getStudyData(){
				let _this = this
				_this.list = []
				getStudy({
					page:1,
					per_page:9999
				}).then(res=>{
					console.log(res)
					if(res.studies){
						res.studies.forEach(item=>{
							if(item.category_title){
								item.tipsHtml = "类型 "+item.category_title
							}
						})
						_this.list = res.studies
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list-container{
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		.newlist{
			background-color: #fff;
		}
	}
</style>